//1.引入样式表
//公用样式 
require('../../assets/css/index.less');
require('../../assets/fonts/iconfont.css');
// 当前页面样式
require('./home.less')

//ES6方式
import Swiper, { Pagination, Autoplay } from 'swiper';
//引入swiper样式
import 'swiper/swiper-bundle.css';

//2.引入工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');

// 3.当前页面的js
dom.ready(function () {
  //加载底部菜单
  dom.bMenu('home')

  //3.配置插件
  //1.当前轮播图需要使用哪些组件
  Swiper.use([Pagination, Autoplay])
  //2.基本插件配置
  new Swiper('.swiper', {
    // direction: 'vertical', // 垂直切换选项
    loop: true, // 循环模式选项
    autoplay: true,

    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    }
  })


  function getUserInfo() {

    https.get("/api/user/info", function (res) {

      let { errno, data } = res;
      if (errno == 0) {
        let { ranking, badges, clockCount } = data;
        console.log(ranking, badges, clockCount);

        dom.getEle("#rank").innerHTML = ranking;
        dom.getEle("#bad").innerHTML = badges;
        dom.getEle("#days").innerHTML = clockCount;
      }
    })
  }
  getUserInfo()


  function getClock() {
    https.get("/api/user/clockInInfo", function (res) {
      let { errno, data } = res;
      if (errno == 0) {
        dom.getEle("#bradge").innerHTML = data.isClockIn ? "已经打卡" : "今日打卡";
        dom.getEle("#days").innerHTML = clockCount;
      }
    })
  }
  getClock()


  dom.addEvent("#bradge", function () {
    https.post('/api/user/clockIn', {}, function (res) {
      let { errno, message } = res;
      if (errno == 0) {
        alert('打卡成功')
        getClock()
      } else {
        alert('打卡失败')
      }
    }) 
  })
})








